import time

from redis import Redis
from flask import current_app

# from flasky import app
from celery_tasks.main import celery_app


@celery_app.task(bind=True, name='celery_test_task1', retry_backoff=3)
def function_haoshi(self, current_time):
    """用来测试的耗时操作"""
    # app_ctx = app.app_context()
    # app_ctx.push()

    # 连接Redis数据库
    # redis_conn = Redis(**current_app.config['REDIS_CONFIG_1'])
    redis_conn = Redis('127.0.0.1', 6379, 0)
    # 模拟耗时操作
    time.sleep(10)
    # 向数据库中存数据
    redis_conn.set('celery_test', current_time, 300)
    # app_ctx.pop()
